# spec file for ROSA Linux
# rpmbuild --define "_sourcedir $PWD" -bb *.spec
# or: abf rpmbuild

Summary:	simple-google-sheet-watcher
Name:		simple-google-sheet-watcher
Version:	1
Release:	2
License:	GPLv3
Group:		Networking/Other
Url:		https://hub.mos.ru/mikhailnov/simple-google-sheet-watcher
Source0:	simple-google-sheet-watcher.py
BuildArch:	noarch
Requires:	python3
Requires:	python3-openpyxl
Requires:	curl

%description
%{summary}

%files
%{_bindir}/%{name}
%config(noreplace) /etc/sysconfig/%{name}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}.timer

%post
%systemd_post %{name}.timer

%preun
%systemd_preun %{name}.timer

#------------------------------------------------------------------

%prep
%setup -T -c

%install
mkdir -p %{buildroot}%{_bindir}
install -m 755 %{SOURCE0} %{buildroot}%{_bindir}/%{name}

mkdir -p %{buildroot}/etc/sysconfig
cat > %{buildroot}/etc/sysconfig/%{name} << 'EOF'
GOOGLE_TABLE_ID=
TG_API_KEY=
TG_CHAT_ID=
EOF

mkdir -p %{buildroot}%{_unitdir}
cat > %{buildroot}%{_unitdir}/%{name}.service << 'EOF'
[Unit]
Description=%{name}

[Service]
Type=oneshot
RemainAfterExit=no
User=nobody
EnvironmentFile=-/etc/sysconfig/%{name}
ExecStart=%{name}
EOF

cat > %{buildroot}%{_unitdir}/%{name}.timer << 'EOF'
[Unit]
Description=%{name}

[Timer]
# раз в 15 минут
OnCalendar=*:0/15

[Install]
WantedBy=timers.target
EOF
